

* This do-file creates a dataset of party pairs where the traditional measures (but not necessarily
* the semantic measures are available); i.e., it includes party pairs even if manifesto content data
* are not available. 



* There are a few party pairs in the R-downloaded corpus with traditional measures that are
* not in "MPDataset_MPDS2023a_stata14.dta"; these will be added too
use "main_analysis_data.dta", clear

gen party1_party2 = party1 + " " + party2
gen party2_party1 = party2 + " " + party1

keep countryname date year party1_party2 party2_party1 pop_temp pop pop_vote_share ///
 inflation gdp_pc unemp institutions diff_combo diff_multicult leader
 
save "temp_match.dta", replace



import excel "manifestos\leaders_extended.xls", sheet("Sheet1") firstrow clear
rename incumbent_leader leader
save "leader_temp.dta", replace



use "manifestos\MPDataset_MPDS2023a_stata14.dta", clear

gen diff_multicult = per607 - per608
gen diff_combo = per504 + per506 + per503 - per505 - per507
drop if missing(diff_multicult) | missing(diff_combo) | missing(pervote)
drop if date > 201812

keep countryname date pervote party partyname diff_multicult diff_combo

bysort party: egen mean_pervote = mean(pervote)
drop if mean_pervote < 5
drop mean_pervote

merge m:1 countryname date partyname using "leader_temp.dta"
drop if _merge == 2
drop _merge


preserve
rename party party2
rename partyname partyname2
rename pervote pervote2
rename diff_multicult diff_multicult2
rename diff_combo diff_combo2
rename leader leader2

tempfile copy
save `copy'

restore
joinby countryname date using `copy'

rename party party1
rename partyname partyname1
rename pervote pervote1
rename leader leader1
rename diff_multicult diff_multicult1
rename diff_combo diff_combo1

drop if party1 == party2

sort countryname date party1 party2

gen year = int(date/100)

merge m:1 countryname year using "other_raw_data/institutions_macro_merge.dta"
keep if _merge == 3
drop _merge
drop if missing(inflation) | missing(gdp_pc) | missing(unemp) | missing(institutions)
drop if countryname == "Switzerland"

* identify and drop duplicate pairs
rowsort party1 party2, gen(temp1 temp2)
tostring(temp1), replace
tostring(temp2), replace
tostring(date), gen(date_string)
gen pair = temp1 + ("x") + temp2 + ("x") + date_string
duplicates drop pair, force
drop temp1 temp2 pair



**** create indicators for treated elections (only difference to core dataset: Koizumi 2001-2006)
gen pop_temp_left = 0
gen pop_temp_right = 0

* Kirchner 2003-2007
replace pop_temp_left = 1 if date == 200710 & countryname == "Argentina"
* Fernandez 2007-2015
replace pop_temp_left = 1 if date == 200906 & countryname == "Argentina"
replace pop_temp_left = 1 if date == 201110 & countryname == "Argentina"
replace pop_temp_left = 1 if date == 201310 & countryname == "Argentina"
replace pop_temp_left = 1 if date == 201510 & countryname == "Argentina"
* Morales 2006-2018
replace pop_temp_left = 1 if date == 200912 & countryname == "Bolivia"
replace pop_temp_left = 1 if date == 201410 & countryname == "Bolivia"
* Correa 2007-2017
replace pop_temp_left = 1 if date == 200904 & countryname == "Ecuador"
replace pop_temp_left = 1 if date == 201302 & countryname == "Ecuador"
replace pop_temp_left = 1 if date == 201702 & countryname == "Ecuador"
* Tsipras 2015-2018
replace pop_temp_left = 1 if date == 201509 & countryname == "Greece"
* Fico 2006-2010; 2012-2018
replace pop_temp_left = 1 if date == 201006 & countryname == "Slovakia"
replace pop_temp_left = 1 if date == 201603 & countryname == "Slovakia"
* Zuma 2009-2018
replace pop_temp_left = 1 if date == 201405 & countryname == "South Africa"


* Menem 1989-1999
replace pop_temp_right = 1 if date == 199505 & countryname == "Argentina"
replace pop_temp_right = 1 if date == 199910 & countryname == "Argentina"
* Borisov 2009-2013; 2014-2017; 2017-2018
replace pop_temp_right = 1 if date == 201305 & countryname == "Bulgaria"
replace pop_temp_right = 1 if date == 201703 & countryname == "Bulgaria"
* Orban 2010-2018
replace pop_temp_right = 1 if date == 201404 & countryname == "Hungary"
replace pop_temp_right = 1 if date == 201804 & countryname == "Hungary"
* Netanyahu 1996-1999; 2009-2018
replace pop_temp_right = 1 if date == 199905 & countryname == "Israel"
replace pop_temp_right = 1 if date == 201301 & countryname == "Israel"
replace pop_temp_right = 1 if date == 201503 & countryname == "Israel"
* Berlusconi 2001-2006; 2008-2011         
replace pop_temp_right = 1 if date == 200604 & countryname == "Italy"
* Muldoon 1975-1984
replace pop_temp_right = 1 if date == 197811 & countryname == "New Zealand"
replace pop_temp_right = 1 if date == 198111 & countryname == "New Zealand"
replace pop_temp_right = 1 if date == 198407 & countryname == "New Zealand"
* Kaczynskis 2005-2007; 2015-2018
replace pop_temp_right = 1 if date == 200710 & countryname == "Poland"
* Meciar 1990-1991; 1992-1994; 1994-1998
replace pop_temp_right = 1 if date == 199409 & countryname == "Slovakia"
replace pop_temp_right = 1 if date == 199809 & countryname == "Slovakia"
* Erdogan 2003-2018
replace pop_temp_right = 1 if date == 200707 & countryname == "Turkey"
replace pop_temp_right = 1 if date == 201106 & countryname == "Turkey"
replace pop_temp_right = 1 if date == 201506 & countryname == "Turkey"
replace pop_temp_right = 1 if date == 201511 & countryname == "Turkey"
replace pop_temp_right = 1 if date == 201806 & countryname == "Turkey"
* Koizumi 2001-2006
replace pop_temp_right = 1 if date == 200311 & countryname == "Japan" // NEW
replace pop_temp_right = 1 if date == 200509 & countryname == "Japan" // NEW





***********************************
* tag and drop populists' parties *
***********************************

gen pop_party = 0

* Kirchner 2003-2007
replace pop_party = 1 if date == 200710 & countryname == "Argentina" & (partyname1 == "Front for Victory" | partyname2 == "Front for Victory")
* Fernandez 2007-2015
replace pop_party = 1 if date == 200906 & countryname == "Argentina" & (partyname1 == "Front for Victory" | partyname2 == "Front for Victory")
replace pop_party = 1 if date == 201110 & countryname == "Argentina" & (partyname1 == "Front for Victory" | partyname2 == "Front for Victory")
replace pop_party = 1 if date == 201310 & countryname == "Argentina" & (partyname1 == "Front for Victory" | partyname2 == "Front for Victory")
replace pop_party = 1 if date == 201510 & countryname == "Argentina" & (partyname1 == "Front for Victory" | partyname2 == "Front for Victory")
* Morales 2006-2018
replace pop_party = 1 if date == 200912 & countryname == "Bolivia" & (partyname1 == "Movement towards Socialism - Political Instrument for the Sovereignty of the Peoples" | partyname2 == "Movement towards Socialism - Political Instrument for the Sovereignty of the Peoples")
replace pop_party = 1 if date == 201410 & countryname == "Bolivia" & (partyname1 == "Movement towards Socialism - Political Instrument for the Sovereignty of the Peoples" | partyname2 == "Movement towards Socialism - Political Instrument for the Sovereignty of the Peoples")
* Tsipras 2015-2018
replace pop_party = 1 if date == 201509 & countryname == "Greece" & (partyname1 == "Coalition of the Radical Left" | partyname2 == "Coalition of the Radical Left")
* Fico 2006-2010; 2012-2018
replace pop_party = 1 if date == 201006 & countryname == "Slovakia" & (partyname1 == "Direction-Social Democracy" | partyname2 == "Direction-Social Democracy")
replace pop_party = 1 if date == 201603 & countryname == "Slovakia" & (partyname1 == "Direction-Social Democracy" | partyname2 == "Direction-Social Democracy")
* Zuma 2009-2018
replace pop_party = 1 if date == 201405 & countryname == "South Africa" & (partyname1 == "African National Congress" | partyname2 == "African National Congress")

* Menem 1989-1999
replace pop_party = 1 if date == 199505 & countryname == "Argentina" & (partyname1 == "Justicialist Party" | partyname2 == "Justicialist Party")
replace pop_party = 1 if date == 199910 & countryname == "Argentina" & (partyname1 == "Justicialist Coalition for Change" | partyname2 == "Justicialist Coalition for Change")
* Borisov 2009-2013; 2014-2017; 2017-2018
replace pop_party = 1 if date == 201305 & countryname == "Bulgaria" & (partyname1 == "Citizens for European Development of Bulgaria" | partyname2 == "Citizens for European Development of Bulgaria")
replace pop_party = 1 if date == 201703 & countryname == "Bulgaria" & (partyname1 == "Citizens for European Development of Bulgaria" | partyname2 == "Citizens for European Development of Bulgaria")
* Orban 2010-2018
replace pop_party = 1 if date == 201404 & countryname == "Hungary" & (partyname1 == "Alliance of Federation of Young Democrats - Hungarian Civic Union - Christian Democratic People's Party" | partyname2 == "Alliance of Federation of Young Democrats - Hungarian Civic Union - Christian Democratic People's Party")
replace pop_party = 1 if date == 201804 & countryname == "Hungary" & (partyname1 == "Alliance of Federation of Young Democrats - Christian Democratic People's Party" | partyname2 == "Alliance of Federation of Young Democrats - Christian Democratic People's Party")
* Netanyahu 1996-1999; 2009-2018
replace pop_party = 1 if date == 199905 & countryname == "Israel" & (partyname1 == "The Consolidation" | partyname2 == "The Consolidation")
replace pop_party = 1 if date == 201301 & countryname == "Israel" & (partyname1 == "The Consolidation" | partyname2 == "The Consolidation")
replace pop_party = 1 if date == 201503 & countryname == "Israel" & (partyname1 == "The Consolidation" | partyname2 == "The Consolidation")
* Berlusconi 2001-2006; 2008-2011         
replace pop_party = 1 if date == 200604 & countryname == "Italy" & (partyname1 == "Go Italy" | partyname2 == "Go Italy")
* Kaczynskis 2005-2007; 2015-2018
replace pop_party = 1 if date == 200710 & countryname == "Poland" & (partyname1 == "Law and Justice" | partyname2 == "Law and Justice")
* Meciar 1990-1991; 1992-1994; 1994-1998
replace pop_party = 1 if date == 199409 & countryname == "Slovakia" & (partyname1 == "Movement for a Democratic Slovakia" | partyname2 == "Movement for a Democratic Slovakia")
replace pop_party = 1 if date == 199809 & countryname == "Slovakia" & (partyname1 == "Movement for a Democratic Slovakia" | partyname2 == "Movement for a Democratic Slovakia")
* Erdogan 2003-2018
replace pop_party = 1 if date == 200707 & countryname == "Turkey" & (partyname1 == "Justice and Development Party" | partyname2 == "Justice and Development Party")
replace pop_party = 1 if date == 201106 & countryname == "Turkey" & (partyname1 == "Justice and Development Party" | partyname2 == "Justice and Development Party")
replace pop_party = 1 if date == 201506 & countryname == "Turkey" & (partyname1 == "Justice and Development Party" | partyname2 == "Justice and Development Party")
replace pop_party = 1 if date == 201511 & countryname == "Turkey" & (partyname1 == "Justice and Development Party" | partyname2 == "Justice and Development Party")
replace pop_party = 1 if date == 201806 & countryname == "Turkey" & (partyname1 == "Justice and Development Party" | partyname2 == "Justice and Development Party")
* Koizumi 2001-2006
replace pop_party = 1 if countryname == "Japan" & date == 200311 & (partyname1 == "Liberal Democratic Party" | partyname2 == "Liberal Democratic Party")
replace pop_party = 1 if countryname == "Japan" & date == 200509 & (partyname1 == "Liberal Democratic Party" | partyname2 == "Liberal Democratic Party")

drop if pop_party == 1
drop pop_party



** create country_id
egen country_id = group(countryname)

* add pop_vote_share

**//Grzymala-Busse, A., & McFaul, M. (2020). Votes for Populists. Codebook', Global Populisms Project, Stanford University, available at https://fsi-live. s3. us-west-1. amazonaws. com/s3fs-public/votes_for_populists_ codebook_0. pdf.

gen pop_vote_share = 0

*Argentina
replace pop_vote_share = 44.684 if date_string == "198905" & country_id == 2

*Austria
replace pop_vote_share = 5.41 if date_string == "197510" & country_id == 5
replace pop_vote_share = 6.06 if date_string == "197905" & country_id == 5
replace pop_vote_share = 4.98 if date_string == "198304" & country_id == 5
replace pop_vote_share = 9.73 if date_string == "198611" & country_id == 5
replace pop_vote_share = 16.64 if date_string == "199010" & country_id == 5
replace pop_vote_share = 22.50 if date_string == "199410" & country_id == 5
replace pop_vote_share = 21.89 if date_string == "199512" & country_id == 5
replace pop_vote_share = 26.91 if date_string == "199910" & country_id == 5
replace pop_vote_share = 10.01 if date_string == "200211" & country_id == 5 
replace pop_vote_share = 15.15 if date_string == "200610" & country_id == 5
replace pop_vote_share = 28.24 if date_string == "200809" & country_id == 5
replace pop_vote_share = 20.506 if date_string == "201309" & country_id == 5
replace pop_vote_share = 25.966 if date_string == "201710" & country_id == 5


*Belgium
replace pop_vote_share = 1.37 if date_string == "197812" & country_id == 7
replace pop_vote_share = 1.10 if date_string == "198111" & country_id == 7
replace pop_vote_share = 1.41 if date_string == "198510" & country_id == 7
replace pop_vote_share = 1.80 if date_string == "198712" & country_id == 7
replace pop_vote_share = 6.58 if date_string == "199111" & country_id == 7
replace pop_vote_share = 7.83 if date_string == "199505" & country_id == 7
replace pop_vote_share = 9.87 if date_string == "199906" & country_id == 7
replace pop_vote_share = 11.68 if date_string == "200305" & country_id == 7
replace pop_vote_share = 11.99 if date_string == "200706" & country_id == 7
replace pop_vote_share = 7.763 if date_string == "201006" & country_id == 7
replace pop_vote_share = 3.673 if date_string == "201405" & country_id == 7

*Bulgaria
replace pop_vote_share = 42.74 if date_string == "200106" & country_id == 10
replace pop_vote_share = 28.02 if date_string == "200506" & country_id == 10
replace pop_vote_share = 49.084 if date_string == "200907" & country_id == 10
replace pop_vote_share =7.298 if date_string == "201305" & country_id == 10
replace pop_vote_share = 42.876 if date_string == "201410" & country_id == 10


*Croatia
replace pop_vote_share = 5.19 if date_string == "200001" & country_id == 13
replace pop_vote_share = 40.313  if date_string == "200311" & country_id == 13
replace pop_vote_share = 36.552  if date_string == "200711" & country_id == 13
replace pop_vote_share = 23.919  if date_string == "201112" & country_id == 13
replace pop_vote_share = 32.911  if date_string == "201609" & country_id == 13

*Czech Republic
replace pop_vote_share = 14.02  if date_string == "199206" & country_id == 15     // Rally for the Republic - Republican Party of Czechoslovakia not in our data
replace pop_vote_share = 10.33 if date_string == "199605" & country_id == 15 
replace pop_vote_share = 11.03 if date_string == "199806" & country_id == 15 
replace pop_vote_share = 18.51 if date_string == "200206" & country_id == 15 
replace pop_vote_share = 12.81  if date_string == "200606" & country_id == 15
replace pop_vote_share = 22.15  if date_string == "201005" & country_id == 15
replace pop_vote_share = 33.567  if date_string == "201310" & country_id == 15
replace pop_vote_share = 48.052 if date_string == "201710" & country_id == 15


*Denmark
replace pop_vote_share = 15.89 if date_string == "197312" & country_id == 16
replace pop_vote_share = 13.58 if date_string == "197501" & country_id == 16
replace pop_vote_share = 14.61 if date_string == "197702" & country_id == 16
replace pop_vote_share = 11.01 if date_string == "197910" & country_id == 16
replace pop_vote_share = 8.91 if date_string == "198112" & country_id == 16
replace pop_vote_share = 3.59 if date_string == "198401" & country_id == 16
replace pop_vote_share = 4.77 if date_string == "198709" & country_id == 16
replace pop_vote_share = 8.96 if date_string == "198805" & country_id == 16
replace pop_vote_share = 6.43 if date_string == "199012" & country_id == 16
replace pop_vote_share = 6.43 if date_string == "199409" & country_id == 16
replace pop_vote_share = 7.41 if date_string == "199803" & country_id == 16
replace pop_vote_share = 13.253 if date_string == "200502" & country_id == 16
replace pop_vote_share = 13.86 if date_string == "200711" & country_id == 16
replace pop_vote_share = 12.303 if date_string == "201109" & country_id == 16
replace pop_vote_share = 21.078 if date_string == "201506" & country_id == 16

*Estonia
replace pop_vote_share = 16.09 if date_string == "199903" & country_id == 17
replace pop_vote_share = 7.30 if date_string == "200303" & country_id == 17
replace pop_vote_share = 17.87 if date_string == "200703" & country_id == 17
replace pop_vote_share = 20.521 if date_string == "201103" & country_id == 17
replace pop_vote_share = 13.7 if date_string == "201503" & country_id == 17


*Finland
replace pop_vote_share = 3.59 if date_string == "197509" & country_id == 18
replace pop_vote_share = 4.58 if date_string == "197903" & country_id == 18
replace pop_vote_share = 9.69 if date_string == "198303" & country_id == 18
replace pop_vote_share = 6.32 if date_string == "198703" & country_id == 18
replace pop_vote_share = 1.30 if date_string == "199503" & country_id == 18
replace pop_vote_share = 0.99 if date_string == "199903" & country_id == 18
replace pop_vote_share = 1.57 if date_string == "200303" & country_id == 18
replace pop_vote_share = 4.05 if date_string == "200703" & country_id == 18
replace pop_vote_share = 19.053 if date_string == "201104" & country_id == 18
replace pop_vote_share = 17.654 if date_string == "201504" & country_id == 18

*France
replace pop_vote_share = 9.83 if date_string == "198603" & country_id == 19
replace pop_vote_share = 9.79 if date_string == "198806" & country_id == 19
replace pop_vote_share = 12.68 if date_string == "199303" & country_id == 19
replace pop_vote_share = 14.93 if date_string == "199705" & country_id == 19
replace pop_vote_share = 11.12 if date_string == "200206" & country_id == 19
replace pop_vote_share = 4.29 if date_string == "200706" & country_id == 19
replace pop_vote_share = 13.596 if date_string == "201206" & country_id == 19
replace pop_vote_share = 13.2 if date_string == "201706" & country_id == 19

*Georgia
replace pop_vote_share = 5.007 if date_string == "201610" & country_id == 20

*Germany
replace pop_vote_share = 8.709 if date_string == "200509" & country_id == 21
replace pop_vote_share = 11.888 if date_string == "200909" & country_id == 21
replace pop_vote_share = 8.6 if date_string == "201309" & country_id == 21
replace pop_vote_share = 21.875 if date_string == "201709" & country_id == 21

*Greece
replace pop_vote_share = 10.94 if date_string == "198110" &  country_id == 22
replace pop_vote_share = 9.89 if date_string == "198506" &  country_id == 22
replace pop_vote_share = 13.13 if date_string == "198906" &  country_id == 22
replace pop_vote_share = 10.28 if date_string == "199004" &  country_id == 22
replace pop_vote_share = 4.54 if date_string == "199310" &  country_id == 22
replace pop_vote_share = 10.73 if date_string == "199609" &  country_id == 22
replace pop_vote_share = 8.73 if date_string == "200004" &  country_id == 22
replace pop_vote_share = 5.896 if date_string == "200403" &  country_id == 22
replace pop_vote_share = 12.143 if date_string == "200910" & country_id == 22
replace pop_vote_share = 28.204 if date_string == "201205" & country_id == 22
replace pop_vote_share = 38.31 if date_string == "201206" & country_id == 22
replace pop_vote_share = 47.817 if date_string == "201501" & country_id == 22
replace pop_vote_share = 5.42 if date_string == "201509" & country_id == 22

*Hungary
replace pop_vote_share = 33.74 if date_string == "199805" & country_id == 23
replace pop_vote_share = 41.07 if date_string == "200204" & country_id == 23
replace pop_vote_share = 42.49 if date_string == "200604" & country_id == 23
replace pop_vote_share = 80.06 if date_string == "201004" & country_id == 23
replace pop_vote_share = 20.853 if date_string == "201404" & country_id == 23
replace pop_vote_share = 19.064 if date_string == "201804" & country_id == 23

*Israel
replace pop_vote_share = 33.65 if date_string == "199605" & country_id == 26
replace pop_vote_share = 15.32 if date_string == "199905" & country_id == 26
replace pop_vote_share = 43.13 if date_string == "200301" & country_id == 26
replace pop_vote_share = 27.507 if date_string == "200603" & country_id == 26
replace pop_vote_share = 41.794 if date_string == "200902" & country_id == 26
replace pop_vote_share = 10.842 if date_string == "201503" & country_id == 26

*Italy
replace pop_vote_share = 8.66 if date_string == "199204" & country_id == 27
replace pop_vote_share = 29.66 if date_string == "199403" & country_id == 27
replace pop_vote_share = 30.64 if date_string == "199604" & country_id == 27
replace pop_vote_share = 33.36 if date_string == "200105" & country_id == 27
replace pop_vote_share = 4.58 if date_string == "200604" & country_id == 27
replace pop_vote_share = 45.29 if date_string == "200804" & country_id == 27
replace pop_vote_share = 50.982 if date_string == "201302" & country_id == 27
replace pop_vote_share = 63.178 if date_string == "201803" & country_id == 27

*Japan
replace pop_vote_share = 20.38 if date_string == "201212" & country_id == 28
replace pop_vote_share = 15.72 if date_string == "201412" & country_id == 28
replace pop_vote_share = 6.075 if date_string == "201710" & country_id == 28


*Latvia
replace pop_vote_share = 14.73 if date_string == "199810" & country_id == 29
replace pop_vote_share = 5.39 if date_string == "200210" & country_id == 29
replace pop_vote_share = 6.941 if date_string == "200610" & country_id == 29
replace pop_vote_share = 7.835 if date_string == "201010" & country_id == 29
replace pop_vote_share = 14.006 if date_string == "201109" & country_id == 29
replace pop_vote_share = 16.719 if date_string == "201410" & country_id == 29
replace pop_vote_share = 11.08 if date_string == "201810" & country_id == 29


*Lithuania
replace pop_vote_share = 31.34 if date_string == "199610" & country_id == 30
replace pop_vote_share = 8.62 if date_string == "200010" & country_id == 30
replace pop_vote_share = 43.22 if date_string == "200410" & country_id == 30
replace pop_vote_share = 32.392 if date_string == "200810" & country_id == 30
replace pop_vote_share = 52.412 if date_string == "201210" & country_id == 30
replace pop_vote_share = 28.184 if date_string == "201610" & country_id == 30

*Mexico
replace pop_vote_share = 51.23 if date_string == "198807" & country_id == 33
replace pop_vote_share = 61.47 if date_string == "199108" & country_id == 33
replace pop_vote_share = 50.28 if date_string == "199408" & country_id == 33
replace pop_vote_share = 39.12 if date_string == "199707" & country_id == 33
replace pop_vote_share = 35.11 if date_string == "200007" & country_id == 33
replace pop_vote_share = 34.522 if date_string == "200306" & country_id == 33
replace pop_vote_share = 12.891 if date_string == "200907" & country_id == 33
replace pop_vote_share = 19.357 if date_string == "201207" & country_id == 33
replace pop_vote_share = 8.813 if date_string == "201506" & country_id == 33
replace pop_vote_share = 38.797 if date_string == "201807" & country_id == 33	

*Moldova		
replace pop_vote_share = 20.513 if date_string == "201411" & country_id == 34	

*Netherlands
replace pop_vote_share = 22.90 if date_string == "200205" & country_id == 36
replace pop_vote_share = 12.04 if date_string == "200301" & country_id == 36
replace pop_vote_share = 22.465 if date_string == "200611" & country_id == 36
replace pop_vote_share = 25.28 if date_string == "201006" & country_id == 36
replace pop_vote_share = 19.737 if date_string == "201209" & country_id == 36
replace pop_vote_share = 22.143 if date_string == "201703" & country_id == 36

*North Macedonia
replace pop_vote_share = 28.10 if date_string == "199810" & country_id == 38
replace pop_vote_share = 20.5 if date_string == "200209" & country_id == 38
replace pop_vote_share = 6.091 if date_string == "200607" & country_id == 38
replace pop_vote_share = 39.949 if date_string == "200806" & country_id == 38
replace pop_vote_share = 32.714 if date_string == "201106" & country_id == 38
replace pop_vote_share = 44.467 if date_string == "201404" & country_id == 38
replace pop_vote_share = 39.392 if date_string == "201612" & country_id == 38

*Poland
replace pop_vote_share = 5.41 if date_string == "199309" & country_id == 40
replace pop_vote_share = 5.55 if date_string == "199709" & country_id == 40
replace pop_vote_share = 27.58 if date_string == "200109" & country_id == 40
replace pop_vote_share = 46.37 if date_string == "200509" & country_id == 40
replace pop_vote_share = 29.89 if date_string == "201110" & country_id == 40
replace pop_vote_share = 37.575 if date_string == "201510" & country_id == 40


*Romania
replace pop_vote_share = 11.62 if date_string == "199209" & country_id == 42
replace pop_vote_share = 4.465 if date_string == "199611" & country_id == 42
replace pop_vote_share = 19.485 if date_string == "200011" & country_id == 42
replace pop_vote_share = 44.44 if date_string == "200411" & country_id == 42
replace pop_vote_share = 32.364 if date_string == "200811" & country_id == 42


*Serbia
replace pop_vote_share = 49.22 if date_string == "199709" & country_id == 44
replace pop_vote_share = 8.81 if date_string == "200012" & country_id == 44
replace pop_vote_share = 7.76 if date_string == "200312" & country_id == 44
replace pop_vote_share = 32.14 if date_string == "200701" & country_id == 44
replace pop_vote_share = 30.10 if date_string == "200805" & country_id == 44
replace pop_vote_share = 30.10 if date_string == "200805" & country_id == 44
replace pop_vote_share = 8.344 if date_string == "201604" & country_id == 44

*Slovakia
replace pop_vote_share = 12.75 if date_string == "199409" & country_id == 45
replace pop_vote_share = 9.07 if date_string == "199809" & country_id == 45
replace pop_vote_share = 9.07 if date_string == "199809" & country_id == 45
replace pop_vote_share = 32.96 if date_string == "200209" & country_id == 45
replace pop_vote_share = 40.879 if date_string == "200606" & country_id == 45
replace pop_vote_share = 5.08 if date_string == "201006" & country_id == 45
replace pop_vote_share = 44.417 if date_string == "201203" & country_id == 45
replace pop_vote_share = 8.643 if date_string == "201603" & country_id == 45

*Slovenia
replace pop_vote_share = 15.82 if date_string == "200010" & country_id == 46
replace pop_vote_share = 29.079 if date_string == "200410" & country_id == 46
replace pop_vote_share = 29.257 if date_string == "200809" & country_id == 46
replace pop_vote_share = 26.193 if date_string == "201112" & country_id == 46
replace pop_vote_share = 20.708 if date_string == "201407" & country_id == 46
replace pop_vote_share = 24.918 if date_string == "201806" & country_id == 46

*South Africa
replace pop_vote_share = 66.35 if date_string == "199906" & country_id == 47
replace pop_vote_share = 69.69 if date_string == "200404" & country_id == 47
replace pop_vote_share = 65.89 if date_string == "200904" & country_id == 47

*Spain
replace pop_vote_share = 12.60 if date_string == "201512" & country_id == 48
replace pop_vote_share = 13.42 if date_string == "201606" & country_id == 48

*Sweden
replace pop_vote_share = 6.73 if date_string == "199109" & country_id == 49
replace pop_vote_share = 5.7 if date_string == "201009" & country_id == 49
replace pop_vote_share = 12.857 if date_string == "201409" & country_id == 49
replace pop_vote_share = 17.534 if date_string == "201809" & country_id == 49

*Turkey
replace pop_vote_share = 34.17 if date_string == "200211" & country_id == 50
replace pop_vote_share = 12.752 if date_string == "201506" & country_id == 50
replace pop_vote_share = 11.702 if date_string == "201806" & country_id == 50

*Ukraine
replace pop_vote_share = 24.49  if date_string == "200203" & country_id == 51
replace pop_vote_share = 14.49 if date_string == "200603" & country_id == 51
replace pop_vote_share = 14.81 if date_string == "200709" & country_id == 51
replace pop_vote_share = 10.45 if date_string == "201210" & country_id == 51
replace pop_vote_share = 4.71 if date_string == "201410" & country_id == 51

*UK
replace pop_vote_share = 12.629 if date_string == "201505" & country_id == 49
replace pop_vote_share = 1.845 if date_string == "201706" & country_id == 49





* replace values of inflation gdp_pc unemp institutions pop_vote_share with pre-treatment values 

*Argentina
*Menem
replace gdp_pc = 8473.0266 if country_id==2 & year> 1989 & year <= 1999
replace unemp = 7.3  if country_id==2 & year> 1989 & year <= 1999
replace inflation = 3046.0912 if country_id==2 & year> 1989 & year <= 1999
replace institutions = 1.6373284  if country_id==2 & year> 1989 & year <= 1999
replace pop_vote_share = 44.684 if country_id==2 & year> 1989 & year <= 1999

*Fernandez
replace gdp_pc = 12857.093 if country_id==2 & year> 2007
replace unemp = 8.47 if country_id==2 & year> 2007
replace inflation = 14.939925 if country_id==2 & year> 2007
replace institutions = 1.3445886 if country_id==2 & year> 2007
// Not included populist vote share because the front for victory party is treated in 2009 election and there are no other populist parties competing in the election.

*Bolivia
replace gdp_pc = 2216.5447 if country_id==8 
replace unemp = 5.08  if country_id==8 
replace inflation = 13.66368 if country_id==8 
replace institutions = .98146284  if country_id==8 
//Not included populist vote share because the movement towards socialism party is treated in 2009 election and there are no other populist parties competing in the election.


*Bulgaria
replace gdp_pc = 6294.3853 if country_id==10 & year==2013
replace unemp = 6.82  if country_id==10 & year==2013
replace inflation = 3.8571196 if country_id==10 & year==2013
replace institutions = 1.4245938  if country_id==10 & year==2013
replace pop_vote_share = 49.084  if country_id==10 & year==2013

replace gdp_pc = 6802.8581 if country_id==10 & year>2014
replace unemp = 11.42  if country_id==10 & year>2014
replace inflation = 1.3407402 if country_id==10 & year>2014
replace institutions = 1.3368772  if country_id==10 & year>2014
replace pop_vote_share = 42.876 if country_id==10 & year>2014

*Greece
replace pop_vote_share = 47.817 if date_string == "201509" & country_id == 22
//Not included other macro indicators because election took place two times in the same year (2015) and there are no other years in the sample.

*Hungary
replace gdp_pc = 11307.716 if country_id==23 & year>2010
replace unemp = 11.17 if country_id==23 & year>2010
replace inflation = 2.5325705 if country_id==23 & year>2010
replace institutions = 1.6462477 if country_id==23 & year>2010
replace pop_vote_share = 80.06 if country_id==23 & year>2010

*Israel
*Netanyahu(1996)
replace gdp_pc = 26698.232 if country_id==26 &  year==1999
replace unemp = 8.46 if country_id==26 &  year==1999
replace inflation = 9.228876876134 if country_id==26 &  year==1999
replace institutions= 1.7804776 if country_id==26 &  year==1999
replace pop_vote_share = 33.65 if country_id==26 &  year==1999

*Netanyahu(2009)
replace gdp_pc = 31852.267 if country_id==26 & year>2009
replace unemp = 9.53 if country_id==26 &  year>2009
replace inflation = 4.4192118 if country_id==26 & year>2009
replace institutions= 1.7562466 if country_id==26 &  year>2009
replace pop_vote_share = 41.794 if country_id==26 &  year>2009

*Italy
// Berlusconi(2001)
replace gdp_pc = 32963.671 if country_id==27 &  year==2006
replace unemp = 9.6 if country_id==27 &  year==2006
replace inflation = 3.033592025884 if country_id==27 &  year==2006
replace institutions= 1.7524692  if country_id==27 &  year==2006
replace pop_vote_share = 33.36 if country_id==27 &  year==2006

*Japan
replace gdp_pc = 31430.631 if country_id==28 & year> 2000 & year <= 2005
replace unemp = 4.75  if country_id==28 & year> 2000 & year <= 2005
replace inflation = -1.336260089987  if country_id==28 & year> 2000 & year <= 2005
replace institutions = 1.7631851 if country_id==28 & year> 2000 & year <= 2005
replace pop_vote_share = 28.31 if country_id==28 & year> 2000 & year <= 2005


*Poland 
replace gdp_pc = 8554.6939 if country_id==40 &  year==2007
replace unemp = 17.75 if country_id==40 & year==2007
replace inflation = 2.5591955 if country_id==40 & year==2007
replace institutions = 2.1626031 if country_id==40 &  year==2007
replace pop_vote_share = 46.37 if country_id==40 &  year==2007


*Slovakia
*Meciar (1992)
replace gdp_pc = 6755.60 if country_id==45 & year> 1992 & year <= 1998
replace unemp = 12.2  if country_id==45 & year> 1992 & year <= 1998
replace inflation = 15.57791171969  if country_id==45 & year> 1992 & year <= 1998
replace institutions = 1.5629355 if country_id==45 & year> 1992 & year <= 1998
replace pop_vote_share = 45.19 if country_id==45 & year> 1992 & year <= 1998 

//Fico (2006)
replace gdp_pc = 12395.752 if country_id==45 & year> 2006 & year<= 2010
replace unemp = 13.39 if country_id==45 & year> 2006 & year<= 2010
replace inflation = 2.899074 if country_id==45 & year> 2006 & year<= 2010
replace institutions = 1.8827344 if country_id==45 & year> 2006 & year<= 2010
replace pop_vote_share = 40.879 if country_id==45 & year> 2006 & year<= 2010

//Fico(2012)
replace gdp_pc = 15126.035 if country_id==45 & year> 2012
replace unemp = 13.97 if country_id==45 & year> 2012
replace inflation = 1.2603677 if country_id==45 & year> 2012
replace institutions = 1.9173399 if country_id==45 & year> 2012
replace pop_vote_share = 44.417 if country_id==45 & year> 2012

*South Africa
replace gdp_pc = 5910.789 if country_id==47 &  year>2009
replace unemp = 20.51 if country_id==47 &  year>2009
replace inflation = 8.6630418 if country_id==47 &  year>2009
replace institutions = 1.6730592 if country_id==47 &  year>2009
replace pop_vote_share = 65.89 if country_id==47 &  year>2009


*Turkey
replace gdp_pc = 6291.667 if country_id==50 &  year >2002
replace unemp = 10.35 if country_id==50 & year >2002 
replace inflation = 37.57482083171  if country_id==50 &  year >2002
replace institutions = 1.6708192 if country_id==50 & year >2002 
replace pop_vote_share = 34.17 if country_id==50 &  year >2002




gen diff_combo = abs(diff_combo1 - diff_combo2)
gen diff_multicult = abs(diff_multicult1 - diff_multicult2)
drop diff_combo1 diff_combo2 diff_multicult1 diff_multicult2

drop date
rename date_string date

tostring party1, replace force
tostring party2, replace force

gen party1_party2 = party1 + " " + party2
gen party2_party1 = party2 + " " + party1

gen leader = 0
replace leader = 1 if leader1 == 1 | leader2 == 1

gen pop_temp = 0
replace pop_temp = 1 if pop_temp_left == 1 | pop_temp_right == 1

gen pop = 1
replace pop = 2 if pop_temp_left == 1
replace pop = 3 if pop_temp_right == 1

keep countryname date year party1_party2 party2_party1 pop_temp pop pop_vote_share ///
 inflation gdp_pc unemp institutions diff_combo diff_multicult leader


append using "temp_match.dta", gen(app)
erase "leader_temp.dta"
erase "temp_match.dta"

gsort -app

duplicates tag countryname date year party1_party2, gen(tag)
duplicates drop countryname date year party1_party2, force

replace party1_party2 = party2_party1 if app == 1
duplicates tag countryname date year party1_party2, gen(tag2)
duplicates drop countryname date year party1_party2, force

gen original = 0
replace original = 1 if tag == 1 | tag2 == 1 | app == 1
drop app

egen election_id = group(countryname date)
encode countryname, gen(country_id)

label define pop 1 "Non-populist" 2 "Left populist" ///
                  3 "Right populist", replace
label values pop pop


** clean up
drop tag2 tag party2_party1

order countryname country_id election_id date year party1_party2 diff_combo diff_multicult ///
 leader pop pop_temp pop_vote_share gdp_pc unemp inflation institutions original


label variable countryname "Name of country"
label variable date "Date of election (YYYYMM)"
label variable year "Year of election (YYYY)
label variable party1_party2 "Manifesto Project IDs of party 1 and party 2"
label variable diff_combo "Difference in positions on equality/welfare (traditional measure)"
label variable diff_multicult "Difference in positions on multiculturalism (traditional measure)"
label variable institutions "Quality of institutions (index)"
label variable gdp_pc "GDP per capita (USD)"
label variable inflation "Inflation rate (%)"
label variable unemp "Unemployment rate (%)"
label variable pop "Treatment indicator"
label variable leader "1 if party-pair with a state leader"
label variable country_id "Country ID"
label variable election_id "Election ID"
label variable pop_temp "1 if any populist state leader"
label variable pop_vote_share "Aggregate populist vote share (%)"
label variable original "1 if included in main analysis dataset"

save "traditional_data_extended.dta", replace


